package com.yqg.protection.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

/**
 * mp代码生成器
 *
 * @since 2022-01-26
 */
public class CodeGenerator {

    public static void main(String[] args) {
        generate();
    }

    private static void generate() {
        FastAutoGenerator.create("jdbc:mysql://172.16.1.58:41306/xfdatabase?serverTimezone=GMT%2b8", "root", "123456")
                .globalConfig(builder -> {
                    builder.author("zxf") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D:\\workspace\\xf-service\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.yqg.protection") // 设置父包名
                            .moduleName(null) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:\\workspace\\xf-service\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder().enableLombok();
//                    builder.mapperBuilder().enableMapperAnnotation().build();
                    builder.controllerBuilder().enableHyphenStyle()  // 开启驼峰转连字符
                            .enableRestStyle();  // 开启生成@RestController 控制器
//                    builder.addInclude("equipment","equipment_input_store","historical_data","organization","premission","role",
//                            "role_perm","SIM_input_store","statistics","temporary_data","user","warn_record"); // 设置需要生成的表名
//                    builder.addInclude("current_dq");
//                    builder.addInclude("current_jh");
//                    builder.addInclude("current_ls");
//                    builder.addInclude("current_qg");
//                    builder.addInclude("current_yg");
                    builder.addInclude("warn_dq");
                    builder.addInclude("warn_jh");
                    builder.addInclude("warn_ls");
                    builder.addInclude("warn_qg");
                    builder.addInclude("warn_yg");

                          //  .addTablePrefix("t_", "sys_"); // 设置过滤表前缀
                })
//                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();

    }
}
